if ( window.profileui == undefined) {

    window.profileui = {};

    $(document).ready(function() {


        boot.ready(function(bootMessage) {

            function submitLogin() {

                var message = new Message({
                    "email": $("#userName").val(),
                    "password": $("#password").val()
                });

                message.restCreate(bootMessage.restLink("sessions"), function() {
                    // On success, we go returnTo, or default if no such place
                    var params = $.deparam.querystring();
                    if ( params.returnTo ) {

                        window.location = params.returnTo;
                    } else {

                        window.location = "/profile/index.html";
                    }
                }, function() {

                    $("errorPanel").show();
                })
            }

            logging.log("booted with ", bootMessage);

            $(".js_autosubmit").enterKey(submitLogin);
            $("#login").click(submitLogin);

        })

    })
}
